<!doctype html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css">
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<script src="../res/js/common.js?v=2"></script>
	<script src="../res/js/socket.js"></script>
	<script>
		var department_id = getQst("department_id");
		var fromFollowUp = getQst("fromFollowUp")

		var departmentList, departmentValueList = [];
		var doctor_name = '',
			userJson = '',
			h5token = '',
			userid = '',
			usertype = '';
		var haveFee = 0,
			haveFeeDoctorName = '',
			haveFeeLogType = 0;
		var inquiryType = '';
		//tabbar跳转
		function tabbargo(openid, orgid) {
			$('.weui-tabbar__item').on('click', function () {
				var type = $(this).attr("id");
				console.log(type);
				if (type == "inquiry_index") {
					location.href = "inquiry_doctor_index.htm?orgid=" + orgid + "&openid=" + openid
				} else if (type == "inquiry_doctor") {
					if (!isLogin) {
						$.confirm("请先登录再操作", function () {
							goPage('login.htm');
						}, function () {
							//取消操作
						});
					} else {
						location.href = "inquiry_doctor.htm?orgid=" + orgid + "&openid=" + openid
					}
				} else if (type == "my_doctor_index") {
					if (!isLogin) {
						$.confirm("请先登录再操作", function () {
							goPage('login.htm');
						}, function () {
							//取消操作
						});
					} else {
						location.href = "my_doctor_index.htm?orgid=" + orgid + "&openid=" + openid
					}
				} else {
					location.href = "inquiry_user_personal.htm?orgid=" + orgid + "&openid=" + openid;
				}
			});
		}

		function newGetDepartmentList() {
			newAjaxPost("/h5/index/utilDepartment/getDepartmentListPc", {}, newGetDepartmentListOk);
		}

		function newGetDepartmentListOk(jsonInfo) {
			var data;
			if (jsonInfo.code == 1) {
				data = jsonInfo.data.list;
				departmentList = data
				departmentValueList[0] = '全部科室'
				for (var i = 0; i < data.length; i++) {
					departmentValueList[i + 1] = departmentList[i].departmentName
					if (departmentList[i].id == department_id) {
						$("#mobile").val(departmentList[i].departmentName)
					}
				}
			} else if (jsonInfo.code == 0) {
				setTimeout(function () {
					newGetDepartmentList();
				}, 2000);
			}
		}

		function showDoctor(department_id, Type) {
			if (department_id == '') {
				department_id = 0
			}
			if (Type) {
				inquiryType = Type
			} else {}
			var params = {
				"current": 1,
				"departmentId": department_id,
				"keyWord": doctor_name,
				"parametn": "",
				"inquiryType": inquiryType,
				"size": 100
			}
			newAjaxPost("/h5/doctorInfo/getHomeDoctorList", params, showDoctorOk);
		};

		function showDoctorOk(jsonInfo) {
			// console.log(jsonInfo);
			var doctorListData = '';
			var doctorListData2 = '';
			var doctNums;
			var data;
			//ios跳转用h5token
			userJson = getUserInfo();
			h5token = userJson.h5Token;
			userid = userJson.id;
			usertype = userJson.type;
			if (jsonInfo.code == 1) {
				data = jsonInfo.data.list;
				doctNums = data.length;
				for (var i = 0; i < data.length; i++) {
					if (data[i].isOnline == 1) { //是否在线  0否  1是
						if (doctNums != 0) {
							doctorListData += '<div class="expertlist_map" style="margin:10px">';
							doctorListData += '<div class="expertlist_map_top to_detail" num="0" id="' + data[i].id + '" >';
							doctorListData += '<div class="expertlist_map_img"> <img src="' + data[i].doctorHeadImg +
								'" /> </div>';
							doctorListData += '<div class="doctor_info">';
							doctorListData += '<div class="doctor_name">' + data[i].trueName + '<span>' + data[i]
								.doctorJobTitle + '</span><span style="padding:5px 5px">' + data[i].departmentName +
								'</span><span class="isOnline" style="padding:5px 5px">在线</span></div>';
							doctorListData += '<div class="age">从业年限 <span>' + data[i].workAge + '年</span> 　年龄 <span>' + data[
								i].doctorAge + '岁</span></div>';
							doctorListData += '</div>';
							doctorListData += '</div>';
							doctorListData += '<div class="brief_introduction uni-ellipsis-2 to_detail" num="0" id="' + data[
								i].id + '">' + data[i].doctorSynopsis + '</div>';
							doctorListData +=
								'<div class="view_felx home_icon_img" style="display:flex;-ms-flex-align: center;justify-content: center;">';
							doctorListData +=
								`<div class="advisory" id=${data[i].id} style="border:none;text-align: center;font-weight: bold;">立即咨询</div>`
							doctorListData += '</div>';
							doctorListData += '</div>';
							doctNums--;
						}
					}
				}
				if (doctNums != 0) {
					for (var i = 0; i < data.length; i++) {
						if (data[i].isOnline == 0) {
							if (doctNums != 0) {
								doctorListData2 += '<div class="expertlist_map"  num="0" id="' + data[i].id +
									'" style="margin:10px">';
								doctorListData2 += '<div class="expertlist_map_top to_detail" num="0" id="' + data[i].id +
									'" >';
								doctorListData2 += '<div class="expertlist_map_img"> <img src="' + data[i].doctorHeadImg +
									'" /> </div>';
								doctorListData2 += '<div class="doctor_info">';
								doctorListData2 += '<div class="doctor_name">' + data[i].trueName + '<span>' + data[i]
									.doctorJobTitle + '</span>   <span style="padding:5px 5px">' + data[i].departmentName +
									'</span><span class="noOnline" style="padding:5px 5px">离线</span></div>';
								doctorListData2 += '<div class="age">从业年限 <span>' + data[i].workAge + '年</span> 　年龄 <span>' +
									data[i].doctorAge + '岁</span></div>';
								doctorListData2 += '</div>';
								doctorListData2 += '</div>';
								doctorListData2 +=
									'<div style="word-break:break-all" class="brief_introduction uni-ellipsis-2 to_detail" num="0" id="' +
									data[i].id + '">' + data[i].doctorSynopsis + '</div>';
								doctorListData2 +=
									'<div class="view_felx home_icon_img" style="display:flex;-ms-flex-align: center;justify-content: center;">';
								doctorListData2 +=
									`<div class="advisory" id=${data[i].id} style="border:none;text-align: center;font-weight: bold;">立即咨询</div>`;
								// doctorListData2 += '<div class="schedulingBtn" id="' + data[i].id + '">值班计划</div>';
								// doctorListData2 += '<div class="offline">图文问诊</div>';
								// doctorListData2 += '<div class="offline">视频问诊</div>';
								doctorListData2 += '</div>';
								doctorListData2 += '</div>';
								doctNums--;
							}
						}
					}
				}
				if (doctorListData == '' && doctorListData2 == '') {
					$('#doctorList').html('')
					$(".noFind").show()
				} else {
					$('#doctorList').html(doctorListData + doctorListData2);
					$(".noFind").hide()
				}
				// setTimeout(function () {
				// showDoctor(department_id);
				// }, 15000);
			} else if (jsonInfo.code == 0) {
				msgInfo(jsonInfo.msg);
				// setTimeout(function () {
				// showDoctor(department_id);
				// }, 2000);
			}
			//跳转到医生页面
			$(".to_detail").on("click", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				// if (haveFee == 0) {
				var strGoUrl = 'doctor_home_page.htm?log_type=' + log_type + '&doctor_id=' + doctor_id;
				goPage(strGoUrl);
				// } else {

				// }
			});
			//医生离线提示
			$('.offline').on('click', function () {
				$.alert({
					title: '温馨提示',
					text: '当前医生离线，请选择其他医生',
					onOK: function () {
						//点击确认
					}
				});
			});
			//点击咨询进入医生主页
			$(".advisory").on("click", function () {
				if (!isLogin()) { //判断是否登录
					$.confirm("请先登录再操作", function () {
						goPage('login.htm');
					}, function () {
						//取消操作
					});
				} else {
					goPage('doctor_home_page.htm?doctor_id=' + $(this).attr("id"))
				}

			});
			//查看医生值班计划
			$(".schedulingBtn").on("click", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				goPage('inquiry_doctor_sche.htm?doctor_id=' + doctor_id + "&rand=" + Math.random());
			});
			//视频、图文问诊
			$(".inquiryBtn").on("click", function () {
				log_type = $(this).attr('num');
				doctor_id = $(this).attr('id');
				doctor_name = $(this).attr('docname');
				fee_pay = $(this).attr('pay');
				var strGoUrl;
				if (haveFee == 0) { //没付问诊费
					strGoUrl = 'inquiry_doctor_fee.htm?feepay=' + fee_pay + '&log_type=' + log_type + '&doctor_id=' +
						doctor_id + '&doctor_name=' + doctor_name;
					goPage(strGoUrl);
				} else { //已付问诊费
					if (haveFeeDoctorName == doctor_name && log_type == haveFeeLogType) { //已付费的那个医生
						strGoUrl = 'inquiry_doctor_patient.htm?log_type=' + log_type + '&doctor_id=' + doctor_id +
							'&h5_token=' + h5token + '&user_id=' + userid + '&user_type=' + usertype;
						goPage(strGoUrl);
					} else if (haveFeeDoctorName == doctor_name && log_type != haveFeeLogType) {
						$.alert("您购买的是该医生的另一种问诊！", function () {
							return;
						});
					} else { //不是已付费的那个医生，禁止问诊
						$.alert("本日之内您还有其他医生的问诊没结束，请先完成问诊！", function () {
							return;
						});
					}
				}
			});
		}

		// ---------------3.30
		var openid = getQst("openid").trim();
		var orgid = getQst("orgid").trim();
		$(function () {
			// 导航栏跳转
			tabbargo(openid, orgid);

			//判断是否由首页复诊进来的
			if (fromFollowUp == 1) {
				inquiryType = 4;
				$("#askType").val('复诊')
			}
			// ---------------3.30
			//显示科室
			if(!isNuanHe){
				newGetDepartmentList()
			}else{
				$("#select-department").hide()
			}

			//医生列表
			showDoctor(department_id);
			//搜索操作
			$('#search').click(function () {
				doctor_name = $("#searchInput").val();
				showDoctor(department_id)
			})

			$("#mobile").picker({
				title: "请选择科室",
				cols: [{
					textAlign: 'center',
					values: departmentValueList
				}],
				onClose: function (p, v, d) {
					var k = 0
					for (k; k < departmentValueList.length; k++) {
						if (p.displayValue[0] != '全部科室' && p.displayValue[0] == departmentValueList[k]) {
							department_id = departmentList[k - 1].id;
							break
						} else {
							department_id = 0
						}
					}
					showDoctor(department_id, inquiryType)
				}
			});

			$("#askType").picker({
				title: "选择问诊方式",
				cols: [{
					textAlign: 'center',
					values: ['全部', '图文问诊', '视频问诊', "家庭医生", "复诊"]
				}],
				onClose: function (p, v, d) {
					if (p.value[0] == "图文问诊") {
						inquiryType = 1;
					} else if (p.value[0] == "视频问诊") {
						inquiryType = 2;
					} else if (p.value[0] == "家庭医生") {
						inquiryType = 3;
					} else if (p.value[0] == "全部") {
						inquiryType = "";
					} else {
						inquiryType = 4;
					}
					showDoctor(department_id, inquiryType)
				}
			});

			//返回上页
			$('#btnBack').on("click", function () {
				goPage("inquiry_doctor_index.htm");
			});
			$('.weui-search-bar__box').on('focus', 'input', function () {
				$('.weui-footer').css({
					"position": "static",
					"display": "none"
				});
			})
			$('.weui-search-bar__box').on('blur', 'input', function () {
				$('.weui-footer').css({
					"position": "fixed",
					"display": "block"
				});
			})
			//我的医生未读消息小红点显示
			wsConnection.onMessage = function (msg) {
				if (msg.packageType == 40) {
					console.log(msg.isRead);
					//是否有未读消息0为不显示1为显示
					msgIsRead = msg.isRead
					if (msgIsRead == 0) {

					} else {
						$("#unreadIcon").show()
					}
				}
			}
		});
	</script>
	<style>
		/* html{touch-action: none;} */
		.fixed-top {
			border-bottom: 1px solid #e8e8e8;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 1;
			background: #F6F6F9
		}

		* {
			margin: 0;
			padding: 0;
		}

		.weui-cells {
			padding-bottom: 60px;
		}

		.weui-cell {
			padding: 0;
			margin: 0;
			margin-left: 5px;
			width: 27%;
			margin-bottom: 0;
			display: inline-block;
		}

		.weui-search-bar {
			margin-left: 5px;
			display: flex;
			padding: 0;
			/* width: 35%; */
		}

		.search-form{
			margin-right: 5px;
		}

		.weui-search-bar__cancel-btn {
			position: relative;
			/* top: 56px; */
			/* right: 10px; */
			height: 25px;
			line-height: 25px;
			width: 55px;
		}

		.weui-search-bar__label {
			top: 0px;
			right: 0px;
			bottom: 0px;
			left: 0px;
			border-radius: 5px;
		}

		.weui-select {
			z-index: 0;
			height: 30px;
			line-height: 30px;
		}

		.weui-search-bar__box .weui-search-bar__input {
			width: 80%;
		}

		.weui-search-bar__box .weui-icon-clear {
			right: 24px;
		}

		.weui-search-bar__box {
			padding-right: 0px;
		}

		.expertlist_map {
			margin: 0;
			margin-bottom: 10px;
		}

		.weui-dialog {
			border-radius: 12px;
		}

		.feeInfoDate span {
			color: #1189FF;
		}

		#start {
			background-color: #ECF6FF;
			height: 40px;
			line-height: 30px;
			margin-top: 10px;
			border-radius: 10px;
		}

		#start span {
			background-color: #1189ff;
			color: #ffffff;
			margin: 0 5px;
			margin-top: 5px;
			width: 30px;
			height: 30px;
			display: inline-block;
			border-radius: 5px;
		}

		#androidDialog1 .weui-mask {
			z-index: 2000;
		}

		.noFind {
			width: 90%;
			margin: 20px 5%;
			display: block;
			text-align: center;
			overflow: hidden;
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #353535;
			background-color: #F9F8FE;
			display: none;
			margin-top: 50px;
		}

		.noFind img {
			width: 198px;
			height: 158px;
			border: none;
			border-radius: 0px;
			margin: 15px;
		}

		#unreadIcon {
			height: 8px;
			width: 8px;
			background-color: red;
			border-radius: 50%;
			position: absolute;
			right: 40px;
		}
	</style>
</head>

<body ontouchstart>
	<div class="fixed-top">
		<div class="weui-btn_primary weui-header">
			<div class="weui-header-left"><a class="icon icon-109" onclick="history.back()"></a></div>
			<h1 class="weui-header-title">权威医生</h1>
		</div>
	</div>
	<div style="margin-top:55px; display: flex; justify-content: space-between;">
		<div class="weui-cell weui-cell_select" id="select-department" style="flex-shrink: 0;">
			<div class="weui-cell__bd">
				<input class="weui-select" id="mobile" type="text" value="全部科室">
			</div>
		</div>
		<div class="weui-cell weui-cell_select">
			<div class="weui-cell__bd">
				<input class="weui-select" id="askType" type="text" value="全部">
			</div>
		</div>
		<!-- 搜索框 -->
		<div class="weui-search-bar weui-search-bar_focusing" id="searchBar">
			<form class="weui-search-bar__form search-form" action="#">
				<div class="weui-search-bar__box">
					<i class="weui-icon-search"></i>
					<input class="weui-search-bar__input" id="searchInput" placeholder="搜索医生" required="" type="search">
					<a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
				</div>
			</form>
			<a href="javascript:" class="weui-search-bar__cancel-btn" id="search">搜索</a>
		</div>
	</div>
	<div class="weui-cell noFind"><img src="../res/images/img_empty_state@2x.png" alt="">
		<p>抱歉，查无关于此结果的数据~</p>
	</div>
	<div>
		<div class="weui-cells">
			<div id="doctorList" style="margin-buttom:60px">
			</div>
		</div>


		<!--脚部-->
		<div id='tb' class="weui-tab" style="height:auto;">
			<div class="weui-tabbar tab-bottom">
				<a href="javascript:;" class="weui-tabbar__item" id="inquiry_index">
					<span style="display: inline-block;position: relative;">
						<img src="../res/images/acitve_index.png" alt="" class="weui-tabbar__icon">
					</span>
					<p class="weui-tabbar__label">首页</p>
				</a>
				<a href="javascript:;" class="weui-tabbar__item" id="inquiry_doctor">
					<img src="../res/images/wz_icon.png" alt="" class="weui-tabbar__icon">
					<p class="weui-tabbar__label f-blue">问诊</p>
				</a>
				<a href="javascript:;" class="weui-tabbar__item" id="my_doctor_index">
					<span style="display: inline-block;position: relative;">
						<img src="../res/images/icon_doctor.png" class="weui-tabbar__icon">
					</span>
					<span id="unreadIcon" style="display: none;"></span>
					<p class="weui-tabbar__label ">我的医生</p>
				</a>
				<a href="javascript:;" class="weui-tabbar__item" id="inquiry_user_per">
					<img src="../res/images/active_per.png" class="weui-tabbar__icon">
					<p class="weui-tabbar__label">我的</p>
				</a>
				<p></p>
			</div>
		</div>
</body>

</html>